package com.zmht.beike.biz.impl;

import java.io.Serializable;
import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.zmht.beike.biz.IMonthinfoBiz;
import com.zmht.beike.core.BaseBizImpl;
import com.zmht.beike.po.THabit;
import com.zmht.beike.po.TImonthinfo;

public class IMonthinfoBizImpl extends BaseBizImpl implements IMonthinfoBiz {
	/*
	 * 删除记录
	 * (non-Javadoc)
	 * @see com.zmht.beike.biz.IMonthinfoBiz#deleteImonthinfo(java.io.Serializable)
	 */
	public boolean deleteImonthinfo(Serializable id) {
		try{
			Object obj = this.getImonthinfoDAO().findById(TImonthinfo.class, id);
			if(obj!=null){
				this.getImonthinfoDAO().deleteObj(obj);
			}
			}catch(Exception e){
				return false;
			}
		
		return true;
	}
	/*
	 * 获得当前月的 未保存的记录
	 * (non-Javadoc)
	 * @see com.zmht.beike.biz.IMonthinfoBiz#getImonthinfo(java.lang.Integer, java.lang.Integer, int, int)
	 */
	public List getImonthinfo(Integer teacherId, Integer month, int satrtIndex,
			int pageSize) {
		String hql = "from TImonthinfo t where t.teacherId="+teacherId+" and t.iaimId!=null";
		return this.getImonthinfoDAO().findByPage(hql, satrtIndex, pageSize);
	}

	public Integer saveImonthinfo(TImonthinfo monthinfo) {
		try{
			return (Integer)this.getImonthinfoDAO().saveObj(monthinfo);
		}catch(Exception e){
			return 0;
		}
		
	}
	public boolean updateImonthinfo(TImonthinfo monthinfo) {
		try{
			this.getImonthinfoDAO().updateObj(monthinfo);
		}catch(Exception e){
			return false;
		}
		return true;
	}
	/*
	 * 获得记录总数
	 * (non-Javadoc)
	 * @see com.zmht.beike.biz.IMonthinfoBiz#getImonthinfoTotal(java.lang.Integer, java.lang.Integer)
	 */
	public int getImonthinfoTotal(Integer teacherId, Integer month) {
		String hql = "from TImonthinfo t where t.teacherId="+teacherId+" and t.iaimId!=null";
		return this.getImonthinfoDAO().findByHQLObj(hql).size();
	}
	public TImonthinfo findById(Serializable id) {
		
		return (TImonthinfo)this.getImonthinfoDAO().findById(TImonthinfo.class, id);
	}
	public static void main(String [] args){
		ApplicationContext cxt;
		cxt = new ClassPathXmlApplicationContext(new String[]{"spring/spring.xml","spring/spring_dao.xml","spring/spring_beike.xml"});
		IMonthinfoBizImpl biz = (IMonthinfoBizImpl)cxt.getBean("imonthinfoBizTag");
		
		List list = biz.getImonthinfo(3, 1, 0, 100);
		System.out.println(list.size());
	}

}
